< previous page page_547 next page >

Page 547
the normal if necessary to ensure it is an upward-pointing normal. That makes the normal point more or less toward the transformed center of projection.
For each point Q in the first polygon, IsAbove then computes the vector from a fixed point P on the plane to the point Q as shown in Figure 15.10. It evaluates the dot product of this vector and the normal vector. If the result is greater than zero, the vector points in roughly the same direction as the normal vector, so the point lies above the plane. Otherwise, the point lies below the plane.
In Visual Basic, the routine actually checks whether the dot product is less than 0.01. This prevents the program from incorrectly classifying points because of round-off errors. Because you use this routine to compare the faces of a solid, two polygons will often share a common point or edge. The dot product for points in the first polygon that lie within the plane of the second should be zero. After the points have been translated, rotated, scaled, and projected, however, rounding errors sometimes make the value a small negative number. By comparing the value to 0.01 instead of zero, the routine avoids incorrect results that would be caused by rounding errors.
The following code shows the IsAbove function. The IsBelow function, which determines whether a polygon is entirely below another, is very similar. The only difference is that IsBelow uses a downward-pointing normal rather than one that points upward.
e10a6a0a59f035e870d90cca05b85fce.gif
' Return True if this polygon is completely above
' the plane containing target.
Public Function IsAbove(ByVal target As Face3d) As Boolean
Dim nx As Single
Dim ny As Single
Dim nz As Single
Dim px As Single
Dim py As Single
Dim pz As Single
Dim dx As Single
Dim dy As Single
Dim dz As Single
Dim Cx As Single
Dim Cy As Single
Dim Cz As Single
Dim i As Integer

    ' Compute an upward pointing normal to the plane.
    target.TransformedNormalVector nx, ny, nz
    If nz < 0 Then
        nx = -nx
        ny = -ny
        nz = -nz
    End If

    ' Get a point on the plane.
    target.GetTransformedPoint 1, px, py, pz

    ' See if the points in this polygon all lie

 
< previous page page_547 next page >